import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
import matplotlib as mpl

def lineal(x,a,b):
    return a*x+b

plt.rcParams["axes.prop_cycle"] = plt.cycler('color', ['#DBAD1F', '#C213DB', '#DB4F2A', '#0500DB', '#09DB9B', '#B4001B', '#e377c2', '#7f7f7f', '#bcbd22', '#17becf'])
plt.rcParams["axes.prop_cycle"] = plt.cycler('color', ['#30011E','#255C99', '#7EA3CC','#FE938C','#963484' ])

# mpl.rcParams['axes.linewidth'] = 0.5

# mpl.rcParams['xtick.major.size'] = 3
# mpl.rcParams['xtick.major.width'] = 0.5
# mpl.rcParams['ytick.major.size'] = 3
# mpl.rcParams['ytick.major.width'] = 0.5

mpl.rcParams.update({'axes.titlesize' : 'large',
                     'axes.labelsize' : 9,
                     'axes.formatter.use_mathtext': True,
                     'axes.linewidth' : 0.5,
                     'lines.linewidth' : 0.6,
                     'lines.markersize': 10,
                     'hatch.linewidth': 0.25,
                     'patch.antialiased': True,
                     'legend.frameon': True,
                     'legend.fontsize': 8,
                     'legend.handlelength': 1.375,
                     'legend.labelspacing': 0.4,
                      'legend.columnspacing': 1,
                      'legend.facecolor': 'white',
                      'legend.edgecolor': 'white',
                      'legend.framealpha': 1,
                      'legend.title_fontsize': 8,
                      'path.simplify' : True,
                      'savefig.bbox' : 'tight',
                      'savefig.pad_inches' : 0.05
                      })


plt.rc('text', usetex=False)
plt.rc('font', family='serif')
plt.rcParams.update({'font.size': 7,
                     'lines.linewidth': 1,
                     'mathtext.fontset': 'cm',
                     'font.family': 'serif',
                     'font.serif': 'cmr10', 
                     'figure.dpi': 300,
                     'grid.color': (0.5, 0.5, 0.5, 0.3)})


Freq,Fluo_sb,Fluo_deph_fit,Fluo_deph,Fluo_obs,Fluo_boltz = np.load('/home/muri/nubeDF/Documents/codigos/CPT_thermometry/CPT_boltzmann/CPT_ocho_niveles/comparacion_espectros/Fit_8_levels_simulations_sd_0.4_sr_6_detDoppler_-10_T_20.00.npy')




# plt.figure(figsize = (2.1,1.9))

# plt.plot(Freq,Fluo_obs,label = 'OBS',linewidth = 1.6,color='black')
# plt.plot(Freq,Fluo_deph,label = 'Dephasing',linewidth = 1)

# plt.plot(Freq,Fluo_boltz,label = 'Instantaneous',linewidth = 1)
# plt.plot(Freq,Fluo_sb,label = 'Sideband',linewidth = 1)
# plt.plot(Freq,Fluo_deph_fit,':',linewidth = 1,color ='blue' )
# #plt.plot(Freq,Fluo_obs,label = 'OBS',linewidth = 1.2)
# plt.xlabel('T (mK)',labelpad = 1,fontsize=6)
# plt.ylabel('T fitted (mK)',labelpad = 1,fontsize=6)
# plt.tick_params(axis='both',pad=1,labelsize=6)

# plt.grid()
# plt.legend(fontsize = 5)
# plt.tight_layout()

# plt.savefig('Temperature_vs_temperature_fitted.pdf',dpi = 200) 

fig,[ax1,ax2] = plt.subplots(2,1,figsize = (3.25,4),sharex=True)

ax2.plot(Freq,(Fluo_obs-Fluo_obs)*100/Fluo_obs,label = 'OBS',linewidth = 1.6)
deph_plot = ax2.plot(Freq,(Fluo_deph-Fluo_obs)*100/Fluo_obs,label = 'Dephasing',linewidth = 1)
ax2.plot(Freq,(Fluo_boltz-Fluo_obs)*100/Fluo_obs,label = 'Instantaneous',linewidth = 1)
ax2.plot(Freq,(Fluo_sb-Fluo_obs)*100/Fluo_obs,'--',label = 'Sideband',linewidth = 0.7)
ax2.plot(Freq,(Fluo_deph_fit-Fluo_obs)*100/Fluo_obs,':',linewidth = 1,color ='blue' )

ax1.plot(Freq,Fluo_obs*100,label = 'OBS',linewidth = 1.6)
ax1.plot(Freq,Fluo_deph*100,label = 'Dephasing',linewidth = 1)
ax1.plot(Freq,Fluo_boltz*100,label = 'Instantaneous',linewidth = 1)
ax1.plot(Freq,Fluo_sb*100,'--',label = 'Sideband',linewidth = 0.7)
ax1.plot(Freq,Fluo_deph_fit*100,':',linewidth = 1,color ='blue' )

ax1.get_yaxis().set_label_coords(-0.13,0.5)
ax2.get_yaxis().set_label_coords(-0.13,0.5)


# ax2.sharex(ax1)

#plt.plot(Freq,Fluo_obs,label = 'OBS',linewidth = 1.2)
ax2.set_xlabel('$\Delta_2$ (MHz)',labelpad = 1,fontsize=9)
ax1.set_ylabel('Fluorescence (a. u.)',labelpad = 1,fontsize=9)
ax2.set_ylabel('Relative difference (%)',labelpad = 1,fontsize=9)
ax1.tick_params(axis='both',pad=1,labelsize=8)
ax2.tick_params(axis='both',pad=1,labelsize=8)

ax2.grid()
ax1.grid()

ax1.legend(fontsize = 8)
#plt.tight_layout()

plt.savefig('comparison_spectra_test.pdf',dpi = 200) 